package auditenergetic;

import java.io.IOException;

import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import jess.*;
public class CreateFacts

{
 public static int rasp;
 public static Rete engine;
 public static Deftemplate temp1;
 public static Deftemplate temp2;
 public static Deftemplate temp3;
 public static Defrule dr;
 public static Fact f,f1;
 public static int i;

    public CreateFacts ()throws JessException, SAXException, IOException 
    {
	 XMLReader parser = XMLReaderFactory.createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser");
	 XMLReader parser2 = XMLReaderFactory.createXMLReader("com.sun.org.apache.xerces.internal.parsers.SAXParser");
	 parser.setContentHandler(new CEPACC());
	 parser2.setContentHandler(new Calcul_AporturiCaldura());
	 parser.parse("xml/Date_preparare_apa_calda.xml");
	 parser2.parse("xml/Calcul_AporturiCaldura.xml");
	 
	 //creaza motorul jess cu ajutorul clasei Rete
        engine = new Rete();
       
        //definim un template jess cu o denumire data si folosind instanta engine-ului
        temp1 = new Deftemplate("TemperaturaInterioara", "", engine);
        temp2 = new Deftemplate("EnergieIncalzire", "", engine);
        temp3 = new Deftemplate("EmisiiC02", "", engine);
       //adaugam templetului sloturi cu functia addSlot
        temp1.addSlot("Value", Funcall.NIL, "STRING");
        temp2.addSlot("Value",Funcall.NIL, "STRING");
        //dupa ce am definit templateul il adaugam in motorul jess 
        engine.addDeftemplate(temp1);
        engine.addDeftemplate(temp2);
      
        //adaugam fapte pentru templateul creat(un fel de asserturi)
        //cream instanta fapt cu numele templateului
        f = new Fact("TemperaturaInterioara", engine);
        f1 =new Fact("EnergieIncalzire", engine);
        //setam valoarea pentru un slot cu valoarea returnata de functia Compute_acm()   
        f.setSlotValue("Value",new Value( new CEPACC().ComputeQ_acm(),RU.FLOAT));
        f.setSlotValue("Value",new Value(Calcul_AporturiCaldura.Compute(), RU.FLOAT));
        //adaugam faptele engineului jess pentru a fi recunoscute
        engine.assertFact(f);
        engine.assertFact(f1);
        //comenzi jess pentru interpretarea faptelor
        engine.executeCommand("(facts)");
        engine.run();
        
        
        
    }

    public static void main(String args[]) throws JessException, SAXException, IOException
    {
    	
    }
}
    

